<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
		<link rel="stylesheet" href="../../../layuiadmin/layui/css/layui.css" media="all">
		<link rel="stylesheet" href="../../../layuiadmin/style/admin.css" media="all">
		<link rel="stylesheet" href="../../../css/common.css" media="all">
		<style type="text/css">
			.table {
				width: 100%;
				border: 1px solid #e6e6e6;
				text-align: center;
			}

			.table .tr {
				border-top: 1px solid #e6e6e6;
			}

			.table .td,
			.table .th {
				width: 33.33%;
				padding: 5px 0;
			}

			.table .thead,
			.table .tr {
				display: flex;
				cursor: pointer;
			}

			.table .th {
				background: #F2F2F2;
			}

			.sub {
				margin: 10px auto;
				width: 95%;
				background: #f8f8f8;
				border-radius: 5px;
			}

			.sub_tr {
				display: flex;
				margin: auto;
			}
		</style>
	</head>
	<body>
		<div class="layui-fluid">
			<div class="layui-row layui-col-space15">
				<div class="layui-col-md12">
					<div class="layui-card">
						<div class="layui-card-body">
							<!-- 搜索 -->
							<form class="layui-form search" id="form" onsubmit="return false" action="##">
								<!-- <div class="layui-inline search_inline">
									<label class="layui-form-label">复选框：</label>
									<div class="layui-input-inline">
										<input type="radio" name="type" value="1" title="月维度" checked lay-filter="changedata">
										<input type="radio" name="type" value="2" title="日维度" lay-filter="changedata">
									</div>
								</div> -->
								<div class="layui-inline search_inline">
									<label class="layui-form-label">月维度：</label>
									<div class="layui-input-inline">
										<input class="layui-input yue" id="test1" placeholder="月维度" name="dates1" autocomplete="off">
										<!-- <input class="layui-input layui-hide ri" id="test2" placeholder="时间" name="dates2" autocomplete="off"> -->
									</div>
								</div>
								<button class="layui-btn search_inline" lay-submit="" lay-filter="search" data-type="reload">查询</button>
								<button class="layui-btn layui-btn-primary search_inline" type="reset">重置</button>
							</form>
							<!-- 搜索 -->

							<div class="table">
								<div class="thead">
									<span class="th">
										类别
									</span>
									<span class="th">
										交易额
									</span>
									<span class="th">
										收益
									</span>
								</div>
								<div class="tbody" id="showdata"></div>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>

		<script type="text/html" id="getdata">
			<div>
				<div class="tr" onclick="showsub(this)">
					<span class="td">拓展奖</span>
					<span class="td">{{ d.d.data.turnover_direct ? number_format(d.d.data.turnover_direct) : '0.00' }}</span>
					<span class="td" style="color: #FF5722;">{{ d.d.data.profit_direct ? '+' + number_format(d.d.data.profit_direct) : '0.00' }}</span>
				</div>
				<div class="sub layui-hide">
					<div class="sub_tr">
						<span class="td">MPOS</span>
						<span class="td">{{ d.d.data.turnover_direct_vip0 ? number_format(d.d.data.turnover_direct_vip0) : '0.00' }}</span>
						<span class="td">{{ d.d.data.profit_direct_vip0 ? '+' + number_format(d.d.data.profit_direct_vip0) : '0.00' }}</span>
					</div>
					<div class="sub_tr">
						<span class="td">MPOS会员</span>
						<span class="td">{{ d.d.data.turnover_direct_vip1 ? number_format(d.d.data.turnover_direct_vip1) : '0.00' }}</span>
						<span class="td">{{ d.d.data.profit_direct_vip1 ? '+' + number_format(d.d.data.profit_direct_vip1) : '0.00' }}</span>
					</div>
					<div class="sub_tr">
						<span class="td">智能POS</span>
						<span class="td">0.00</span>
						<span class="td">+0.00</span>
					</div>
				</div>
			</div>
			<div>
				<div class="tr" onclick="showsub(this)">
					<span class="td">推广奖</span>
					<span class="td">{{ d.e.data.turnover_indirect ? number_format(d.e.data.turnover_indirect) : '0.00' }}</span>
					<span class="td" style="color: #FF5722;">{{ d.e.data.profit_indirect ? '+' + number_format(d.e.data.profit_indirect) : '0.00' }}</span>
				</div>
				<div class="sub layui-hide">
					<div class="sub_tr">
						<span class="td">MPOS</span>
						<span class="td">{{ d.e.data.turnover_indirect_vip0 ? number_format(d.e.data.turnover_indirect_vip0) : '0.00' }}</span>
						<span class="td">{{ d.e.data.profit_indirect_vip0 ? '+' + number_format(d.e.data.profit_indirect_vip0)  : '0.00' }}</span>
					</div>
					<div class="sub_tr">
						<span class="td">MPOS会员</span>
						<span class="td">{{ d.e.data.turnover_indirect_vip1 ? number_format(d.e.data.turnover_indirect_vip1) : '0.00' }}</span>
						<span class="td">{{ d.e.data.profit_indirect_vip1 ? '+' + number_format(d.e.data.profit_indirect_vip1)  : '0.00' }}</span>
					</div>
					<div class="sub_tr">
						<span class="td">智能POS</span>
						<span class="td">0.00</span>
						<span class="td">+0.00</span>
					</div>
				</div>
			</div>
			<div class="tr">
				<span class="td">激活返现</span>
				<span class="td"></span>
				<span class="td" style="color: #FF5722;">{{ d.a.data.profit_direct ? '+' + number_format(d.a.data.profit_direct) : '0.00' }}</span>
			</div>
			<div class="tr">
				<span class="td">会员返佣</span>
				<span class="td"></span>
				<span class="td" style="color: #FF5722;">{{ d.b.data.profit_indirect ? '+' + number_format(d.b.data.profit_indirect) : '0.00' }}</span>
			</div>
			<div class="tr">
				<span class="td">团建返佣</span>
				<span class="td"></span>
				<span class="td" style="color: #FF5722;">{{ d.c.data.profit_indirect ? '+' + number_format(d.c.data.profit_indirect) : '0.00' }}</span>
			</div>
		</script>

		<script src="../../../layuiadmin/layui/layui.js"></script>
		<script src="../../../js/jquery.min.js"></script>
		<script src="../../../js/common.js"></script>
		<script>
			layui.config({
				base: '../../../layuiadmin/' //静态资源所在路径
			}).extend({
				index: 'lib/index' //主入口模块
			}).use(['index', 'table', 'form', 'laytpl', 'laydate'], function() {
				var table = layui.table,
					$ = layui.$,
					form = layui.form,
					laydate = layui.laydate,
					laytpl = layui.laytpl,
					admin = layui.admin;

				var _data = {
					dates: getmonth().replace(/-/ig,''),
					type: 1
				};
				
				initdata();
				
				//监听搜索
				form.on('radio(changedata)', function(data) {
					_data.type = data.value
					if(data.value == 1) {
						$('.yue').removeClass('layui-hide');
						$('.ri').addClass('layui-hide');
					} else {
						$('.yue').addClass('layui-hide');
						$('.ri').removeClass('layui-hide');
					}
				});
				
				laydate.render({
					elem: '#test1',
					type: 'month',
				});
				laydate.render({
					elem: '#test2',
				});

				//监听搜索
				form.verify({
					memberid: function(value, item) { //value：表单的值、item：表单的DOM对象
						if (!value) {
							return '姓名不能为空';
						}
					}
				});

				//监听搜索
				form.on('submit(search)', function(data) {
					if(_data.type == 1){
						_data.dates = data.field.dates1.replace(/-/ig,'')
					} else {
						_data.dates = data.field.dates2.replace(/-/ig,'')
					}
					console.log(data.field);
					initdata();
					return false;
				});

				$("button[type=reset]").on("click", function() {
					_data.dates = getmonth().replace(/-/ig,'')
					$('.yue').removeClass('layui-hide');
					$('.ri').addClass('layui-hide');
					initdata();
					document.getElementById("form").reset();
				});

				function initdata() {
					$.get(server.queryprofit_month, _data, function(res, status) {
						if (status == 'success') {
							if (res.code == 0) {
								var data = res;

								var getTpl = getdata.innerHTML,
									view = document.getElementById('showdata');
								laytpl(getTpl).render(data, function(html) {
									view.innerHTML = html;
								});
							} else {
								layer.msg(res.msg);
							}
						} else {
							layer.msg('服务器连接错误');
						}
					});
				}
				window.showsub = function(_self) {
					$(_self).next().toggleClass('layui-hide');
				}
			});
		</script>
	</body>
</html>